Page({
  data: {
    highBp:0,
    lowBp:0,
    hp:0,
    weight:0,
    bpView:true,
    hpView:true,
    weightView:true,
    hpData :0,
    weightData:0,
    lowBpData:0,
    highBpData :0

  },

//   onLoad: function (options) {
//     console.log(options.bp);
//     console.log(options.hp);
//     console.log(options.weight);
//     var that = this;
//     that.setData({
//       BpView : !options.bp,
//       hpView  : !options.hp,
//       weightView : !options.weight
//   })
//     console.log(that.data.BpView);
// },
onShow: function (options) {
  let pages = getCurrentPages();
  // 数组中索引最大的页面--当前页面
  let currentPage = pages[pages.length - 1];
  // 打印出当前页面中的 options
  console.log(currentPage.options)
  var that = this;
  that.setData({
    bpView : JSON.parse(currentPage.options.bp),
    hpView  : JSON.parse(currentPage.options.hp),
    weightView : JSON.parse(currentPage.options.weight),
    hpData : currentPage.options.hpData==='null'?null: currentPage.options.hpData,
    weightData : currentPage.options.weightData==='null'?null: currentPage.options.weightData,
    lowBpData : currentPage.options.lowBpData==='null'?null: currentPage.options.lowBpData,
    highBpData : currentPage.options.highBpData==='null'?null: currentPage.options.highBpData
  })

  console.log(that.data.bpView);
  console.log(that.data.hpView);
  console.log(that.data.weightView);
},


  inputHighBp:function(e){
    this.setData({
      highBp:e.detail.value
    })
  },

  inputLowBp:function(e){
    this.setData({
      lowBp:e.detail.value
    })
  },

  inputHP:function(e){
    this.setData({
      hp:e.detail.value
    })
  },

  inputWeight:function(e){
    this.setData({
      weight:e.detail.value
    })
  },

  formSubmit(e) {
    console.log('this.highBp',this.data.highBp)
    console.log('this.lowBp',this.data.lowBp)
    console.log('this.hp',this.data.hp)
    console.log('this.weight',this.data.weight)
    wx.request({
      url: 'https://calamar.top:8081/measure/insert', //仅为示例，并非真实的口址
      method: 'post',
      data: {
        userId: 18721260590,
        highBp: this.data.highBp,
        lowBp: this.data.lowBp,
        hp: this.data.hp,
        weight: this.data.weight
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data)
        if(res.data.code ==="000000"){
          wx.showModal({
            title: '温馨提示',
            content: '添加成功',
            showCancel: false,//是否显示取消按钮
            cancelText:"否",//默认是“取消”
            cancelColor:'red',//取消文字的颜色
            confirmText:"确定",//默认是“确定”
            confirmColor: 'pink',//确定文字的颜色
            success: function (res) {
              if (res.cancel) {
                //点击取消,默认隐藏弹框
              } else {
                //点击确定
                // wx.navigateTo({
                //   url: '/pages/healthtest/index',
                // })
                wx.navigateBack({
                  delta:0,
                })
              }
            },
            fail: function (res) { },//接口调用失败的回调函数
            complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
          })
        }else{
          wx.showModal({
            title: '提示', content: res.data.description,
            showCancel: false,//是否显示取消按钮
            cancelText:"否",//默认是“取消”
            cancelColor:'red',//取消文字的颜色
            confirmText:"确定",//默认是“确定”
            confirmColor: 'pink',//确定文字的颜色
          })
        }



      }

    })


  },
})